package main.链表;

import common.ListNode;

/**
 * @author tmh
 * @date 2024/7/19 15:23
 * @description
 */
public class T206反转链表 {
    /**
     * [普通解法]
     * 1.先移动pre指针
     * 2.在移动p当前指针
     * @param head
     * @return
     */
    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode p = head;
        while (p != null) {
            ListNode temp = p.next;
            p.next = pre;
            pre = p;
            p = temp;
        }
        return pre;
    }
}
